package com.xiaoxu.content.controller;

import com.xiaoxu.content.model.dto.SaveTeachplanDto;
import com.xiaoxu.content.model.dto.TeachplanDto;
import com.xiaoxu.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoxu
 * @version 1.0
 * @description 课程计划编辑接口
 * @date 2023/1/17 21:26
 */
@RestController
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
public class TeachplanController {

    private final TeachplanService teachplanService;

    public TeachplanController(TeachplanService teachplanService) {
        this.teachplanService = teachplanService;
    }

    @ApiOperation("查询教学计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanService.findTeachplayTree(courseId);
    }

    @ApiOperation("教学计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan) {
        //执行service
        teachplanService.saveOrUpdateTeachplan(teachplan);
    }

    @ApiOperation("删除教学计划")
    @ApiImplicitParam(value = "id", name = "教学计划Id", required = true, dataType = "Long")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public void deleteTeachplan(@PathVariable Long teachPlanId) {
        //执行service
        teachplanService.deleteTeachplan(teachPlanId);
    }

    @ApiOperation("上移教学计划")
    @ApiImplicitParam(value = "id", name = "教学计划Id", required = true, dataType = "Long")
    @PostMapping("/teachplan/moveup/{teachPlanId}")
    public void moveUpTeachplan(@PathVariable Long teachPlanId) {
        String direction = "up";
        //执行service
        teachplanService.moveTeachplan(teachPlanId, direction);
    }

    @ApiOperation("下移教学计划")
    @ApiImplicitParam(value = "id", name = "教学计划Id", required = true, dataType = "Long")
    @PostMapping("/teachplan/movedown/{teachPlanId}")
    public void moveDownTeachplan(@PathVariable Long teachPlanId) {
        String direction = "down";
        //执行service
        teachplanService.moveTeachplan(teachPlanId, direction);
    }




}
